package com.foxire.lambda;

public class LambdaDemo1 {
    public static void main(String[] args) {
        // 目标：认识匿名内部类和Lambda表达式，搞清楚基本作用
        Animal animal = new Animal() {
            @Override
            public void sleep() {
                System.out.println("sleep");
            }
        };
        animal.sleep();

        // 错误示范:Lambda并不是可以简化全部的匿名内部类,Lambda只能简化函数式接口的匿名内部类。
//        Animal animal2 = () -> {
//            System.out.println("sleep");
//        };
//        animal2.sleep();

        System.out.println("------------------------------------------------");

//        Swim swim1 = new Swim() {
//            @Override
//            public void swim() {
//                System.out.println("swim");
//            }
//        };
//        swim1.swim();

        // Lambda只能简化函数式接口的匿名内部类
        Swim swim2 = () -> {
            System.out.println("swim");
        };
        swim2.swim();

    }
}

abstract class Animal {
    public abstract void sleep();
}

// 函数式接口, 只有一个抽象方法
@FunctionalInterface // 函数式接口注解
interface Swim{
    void swim();
}